#include <QtGui/QApplication>
#include "mainwindow.h"
#include "buycatalog.h"
#include <QtGui/QMessageBox>
#include <QFile>
#include <QTextStream>

void myMessageHandler(QtMsgType type, const char *msg)
{
    QString txt;
    switch (type) {
    case QtDebugMsg:
        txt = QString("Debug: %1").arg(msg);
        break;
    case QtWarningMsg:
        txt = QString("Warning: %1").arg(msg);
        break;
    case QtCriticalMsg:
        txt = QString("Critical: %1").arg(msg);
        break;
    case QtFatalMsg:
        txt = QString("Fatal: %1").arg(msg);
        abort();
    }
    QFile outFile("c:/data/BuyAndDownloadExample.log");
    outFile.open(QIODevice::WriteOnly | QIODevice::Append);
    QTextStream ts(&outFile);
    ts << txt << endl;
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    // NOTE: having debug output to console slows down the app run
    // as out-of-sync result IAP client hungs after getUserAndDeviceId call
    // that is IAP client issue that is not going to be fixed
    // https://support.preminetsolution.com/jira/browse/JUNIPERQA-20973
    //qInstallMsgHandler(myMessageHandler);
    MainWindow w;
    w.listPurchases();
    
#if defined(Q_WS_S60)// || defined (Q_WS_SIMULATOR)
    w.showFullScreen();
#else
    w.show();
#endif
    
    return a.exec();
}
